﻿using System;
using System.Collections.Generic;
using System.Text;
using SysCommon.Entity.Business.DCS.View;

namespace CVSS.Client.BDM.Business
{
    class ShowEntityHelper
    {
        public static void ShowFlowDataInfo<T>(T[] etys,SysCommon.UI.DataGridViewForPageCtrl dgv) where T : new()
        {
            try
            {
                if (typeof(T) == typeof(View_DangerCargo_Ety))
                {
                    View_DangerCargo_Ety[] ds = etys as
                       View_DangerCargo_Ety[];

                    if (ds == null)
                    {
                        ds = new View_DangerCargo_Ety[0];
                    }
                    double totalPage = Convert.ToDouble(ds.Length) / 30;
                    int iTotalPage = Convert.ToInt16(totalPage);
                    if (iTotalPage * 30 < ds.Length)
                    {
                        iTotalPage++;
                    }
                    View_DangerCargo_Ety[] datas =
                        SysCommon.Tools.GetResultFromPage<
                        View_DangerCargo_Ety>.GetPage(
                        ds, 1, 30);
                    dgv.Init(1, iTotalPage, 30, datas);                    
                }
                else if (typeof(T) == typeof(View_Escort_Ety))
                {
                    View_Escort_Ety[] ds = etys as
                        View_Escort_Ety[];
                    if (ds == null)
                    {
                        ds = new View_Escort_Ety[0];
                    }
                    double totalPage = Convert.ToDouble(ds.Length) / 30;
                    int iTotalPage = Convert.ToInt32(totalPage);
                    if (iTotalPage * 30 < ds.Length)
                    {
                        iTotalPage++;
                    }
                    View_Escort_Ety[] datas =
                        SysCommon.Tools.GetResultFromPage<
                        View_Escort_Ety>.GetPage(ds, 1, 30);
                    dgv.Init(1, iTotalPage, 30, datas);
                }
                else if (typeof(T) == typeof(View_DangerCompany_Ety))
                {
                    View_DangerCompany_Ety[] ds = etys as
                        View_DangerCompany_Ety[];
                    if (ds == null)
                    {
                        ds = new View_DangerCompany_Ety[0];
                    }

                    double totalPage = Convert.ToDouble(ds.Length) / 30;
                    int iTotalPage = Convert.ToInt32(totalPage);
                    if (iTotalPage * 30 < ds.Length)
                    {
                        iTotalPage++;
                    }
                    View_DangerCompany_Ety[] datas =
                        SysCommon.Tools.GetResultFromPage<
                        View_DangerCompany_Ety>.GetPage(ds, 1, 30);
                    dgv.Init(1, iTotalPage, 30, datas);
                }
            }
            catch (Exception ex)
            {
                SysCommon.Global.mainLog.Error("调用ShowFlowDataInfo<T>(T[] etys) where T : new()出错", ex);
            }
        }

        public static object SelectionChanged<T>(T[] data, 
            SysCommon.UI.DataGridViewForPageCtrl.OnDataChangedHandlerEventArgs e) where T:new()
        {
            try
            {
                int curPage = e.PageIndex;
                int pageSize = e.PageSize;
                int pageCount = e.TotalPageCount;

                if (data != null)
                {
                    T[] etys = SysCommon.Tools.GetResultFromPage<
                        T>.GetPage(
                        data, curPage, 30);

                    return etys;
                }
            }
            catch (Exception ex)
            {
                SysCommon.Global.mainLog.Error("调用SelectionChanged<T>出错", ex);
            }
            return new T[0];
        }
    }
}
